.\"
.\" Copyright (C) 1994-2021 Altair Engineering, Inc.
.\" For more information, contact Altair at www.altair.com.
.\"
.\" This file is part of both the OpenPBS software ("OpenPBS")
.\" and the PBS Professional ("PBS Pro") software.
.\"
.\" Open Source License Information:
.\"
.\" OpenPBS is free software. You can redistribute it and/or modify it under
.\" the terms of the GNU Affero General Public License as published by the
.\" Free Software Foundation, either version 3 of the License, or (at your
.\" option) any later version.
.\"
.\" OpenPBS is distributed in the hope that it will be useful, but WITHOUT
.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
.\" FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
.\" License for more details.
.\"
.\" You should have received a copy of the GNU Affero General Public License
.\" along with this program.  If not, see <http://www.gnu.org/licenses/>.
.\"
.\" Commercial License Information:
.\"
.\" PBS Pro is commercially licensed software that shares a common core with
.\" the OpenPBS software.  For a copy of the commercial license terms and
.\" conditions, go to: (http://www.pbspro.com/agreement.html) or contact the
.\" Altair Legal Department.
.\"
.\" Altair's dual-license business model allows companies, individuals, and
.\" organizations to create proprietary derivative works of OpenPBS and
.\" distribute them - whether embedded or bundled with other software -
.\" under a commercial license agreement.
.\"
.\" Use of Altair's trademarks, including but not limited to "PBS™",
.\" "OpenPBS®", "PBS Professional®", and "PBS Pro™" and Altair's logos is
.\" subject to Altair's trademark licensing policies.
.\"

.if \n(Pb .ig Ig
.TH pbs_rescquery 3B "" Local "PBS Pro"
.\" The following macros are style for object names and values.
.de Ar		\" command/function arguments and operands (italic)
.ft 2
.if \\n(.$>0 \&\\$1\f1\\$2
..
.de Av		\" data item values  (Helv)
.if  \n(Pb .ft 6
.if !\n(Pb .ft 3
.ps -1
.if \\n(.$>0 \&\\$1\s+1\f1\\$2
..
.de At		\" attribute and data item names (Helv Bold)
.if  \n(Pb .ft 6
.if !\n(Pb .ft 2
.ps -1
.if \\n(.$>0 \&\\$1\s+1\f1\\$2
..
.de Ty		\" Type-ins and examples (typewritter)
.if  \n(Pb .ft 5
.if !\n(Pb .ft 3
.if \\n(.$>0 \&\\$1\f1\\$2
..
.de Er		\" Error values ( [Helv] )
.if  \n(Pb .ft 6
.if !\n(Pb .ft 3
\&\s-1[\^\\$1\^]\s+1\f1\\$2
..
.de Sc		\" Symbolic constants ( {Helv} )
.if  \n(Pb .ft 6
.if !\n(Pb .ft 3
\&\s-1{\^\\$1\^}\s+1\f1\\$2
..
.de Al		\" Attribute list item, like .IP but set font and size
.if !\n(Pb .ig Ig
.ft 6
.IP "\&\s-1\\$1\s+1\f1"
.Ig
.if  \n(Pb .ig Ig
.ft 2
.IP "\&\\$1\s+1\f1"
.Ig
..
.\" the following pair of macros are used to bracket sections of code
.de Cs
.ft 5
.nf
..
.de Ce
.sp
.fi
.ft 1
..
.\" End of macros
.Ig
.SH NAME
pbs_rescquery, avail, totpool, usepool - query resource availability
.SH SYNOPSIS
#include <pbs_error.h>
.br
#include <pbs_ifl.h>
.sp
.ft 3
.nf
int pbs_rescquery\^(\^int\ connect, char\ **resourcelist, int *arraysize,
int *available, int *allocated, int *reserved, int *down \^)
.sp
char *avail\^(\^int connect, char *resc\^)
.sp
int totpool\^(\^int connect, int update\^)
.sp
int usepool\^(\^int connect, int update\^)
.fi
.ft 1
.SH DESCRIPTION
.if \n(Pb .ig Ig
.HP 2
.Ig
.if !\n(Pb .ig Ig
.sp
.Ig
.B pbs_rescquery
.br
Issue a request to the batch server to query the availability of resources.
.Ar connect
is the connection returned by \f3pbs_connect\fP().
.Ar resourcelist
is an array of one or more strings specifying the resources to be queried.
.Ar arraysize
is the is the number of strings in resourcelist.
.Ar available ,
.Ar allocated ,
.Ar reserved ,
and
.Ar down
are integer arrays of size arraysize.  The amount of resource specified in
the corresponding resourcelist string which is available, already allocated,
reserved, and down/off-line is returned in the integer arrays.
.IP
At the present time the only resources which may be specified is "nodes".
It may be specified as
.br
.Ty \ \ \ \ nodes
.br
.Ty \ \ \ \ nodes=
.br
.Ty \ \ \ \ nodes=\f2specification\f1
.br
where specification is what a user specifies in the -l option arguement list
for nodes, see qsub(1B) and the various pbs_resource_* man pages.
.IP
Where the node resourcelist is a simple type, such as "nodes", "nodes=",
or "nodes=\f2type\fP", the numbers returned reflect the actual number of nodes
(of the specified type) which are \f2available\fP, \f2allocated\fP,
\f2reserved\fP, or \f2down\fP.
.IP
For a more complex node resourcelist, such as
"nodes=2" or "nodes=type1:type2", only the value returned in
.I available
has meaning.
If the number in
.I available
is positive, it is the number of nodes required to satisfy the specification
and that some set of nodes are available which will satisfy it, see
.I avail ().
If the number in
.I available
is zero, some number of nodes required for the specification are
currently unavailable, the request might be satisfied at a later time.
If the number in
.I available
is negative, no combination of known nodes can fulfill the specification.
.if \n(Pb .ig Ig
.HP 2
.Ig
.if !\n(Pb .ig Ig
.sp
.Ig
.B avail
.br
The
.I avail ()
call is provided as a conversion aid for schedulers written for early versions
of PBS.   The avail() routine uses pbs_rescquery() and returns a character
string answer.
.Ar connect
is the connection returned by \f3pbs_connect\fP().
.Ar resc
is a single
.I node=specification
specification as discussed above.  If the nodes to satisfy the specification
are currently available, the return value is the character string
.B yes .
If the nodes are currently unavailable, the return is the character string
.B no .
If the specification could never be satisfied, the return is the string
.B never .
An error in the specification returns the character string
.B ? .
.if \n(Pb .ig Ig
.HP 2
.Ig
.if !\n(Pb .ig Ig
.sp
.Ig
.B totpool
.br
The
.I totpool ()
function returns the total number of nodes known to the PBS server.  This is
the sum of the number of nodes available, allocated, reserved, and down.
The parameter
.Ar connection
is the connection returned by pbs_connect().
The parameter
.Ar update
if non-zero, causes totpool() to issue a pbs_rescquery() call to obtain
fresh information.   If zero, numbers from the prior pbs_rescquery() are used.
.if \n(Pb .ig Ig
.HP 2
.Ig
.if !\n(Pb .ig Ig
.sp
.Ig
.B usepool
.br
.I usepool ()
returns the number of nodes currently in use, the sum of allocated, reserved,
and down.
The parameter
.Ar connection
is the connection returned by pbs_connect().
The parameter
.Ar update
if non-zero, causes totpool() to issue a pbs_rescquery() call to obtain
fresh information.   If zero, numbers from the prior pbs_rescquery() are used.
.SH "SEE ALSO"
qsub(1B), pbs_connect(3B), pbs_disconnect(3B), pbs_rescreserve(3B) and
pbs_resources(7B)
.SH DIAGNOSTICS
When the batch request generated by the \f3pbs_rescquery\f1()
function has been completed successfully
by a batch server, the routine will return 0 (zero).
Otherwise, a non zero error is returned.  The error number is also set
in pbs_errno.
.LP
The functions usepool() and totpool() return -1 on error.
